#!/bin/sh
table_name=$1
connstr=$2
type=$3

if [ "${type}"x = "a"x ]
then
   sqlstr="UPDATE ${table_name} SET ODS_SRC_DT=TO_CHAR(to_date(ODS_SRC_DT,'YYYY-MM-DD')-1,'YYYY-MM-DD')"
else
   sqlstr="UPDATE ${table_name}  SET START_DATE=TO_CHAR(TO_DATE(START_DATE,'YYYY-MM-DD')-1,'YYYY-MM-DD'),END_DATE=( case when end_date >='2099-12-28' then end_date else to_char(to_date(end_date,'YYYY-MM-DD')-1,'YYYY-MM-DD') end )"
fi

sqlplus -s ${connstr}<<EOF
SET TIMING OFF
SET HEAD OFF
WHENEVER SQLERROR EXIT SQL.SQLCODE
${sqlstr};
select '${table_name} completed' from dual;
COMMIT;
exit;
EOF

ret=$?
if [  $ret != 0 ]
then
        echo "update table error,table name ${table_name}" |tee -a fix_clpm_src_dt.sh.log
        exit 92
fi
        echo " "
        exit 0 



exit 0
